package com.yj.ccs.abs.boot.config.mybatis.handler;

import com.yj.ccs.abs.common.enums.FileType;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Copyright 2018 (C) Yunjian-VC
 * Created on : 2018/3/16
 * Author     : Unbelievable9
 **/
public class FileTypeHandler extends BaseTypeHandler<FileType> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, FileType fileType, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i, fileType.getValue());
    }

    @Override
    public FileType getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return FileType.fromValue(resultSet.getInt(s));
    }

    @Override
    public FileType getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return FileType.fromValue(resultSet.getInt(i));
    }

    @Override
    public FileType getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return FileType.fromValue(callableStatement.getInt(i));
    }
}
